package com.woniuxy.common;

import org.springframework.cloud.client.ServiceInstance;

import java.util.List;

/**
 * @author : mafan
 * @date : 2020-11-19 14:33
 **/
public class TimesRound implements LoadBalance {

    private int index = 0;
    private int maxTime = 5;
    private int times = 1;

    public ServiceInstance getServer(List<ServiceInstance> instances) {
            if (times < maxTime) {
                times++;
            } else {
                index++;
                times=0;
                if (index > instances.size() - 1) {
                    index = 0;
                }
            }
            ServiceInstance instance = instances.get(index);
            return instance;
    }
}
